<?
// If data is set (i.e the submit button has been hit)
if (isset($data) && $userdata['type'] != 'demo') {
	if (is_array($data)) {
		$data['os'] = explode('/', $data['os']);
		$data['osversion'] = $data['os'][1];
		$data['os'] = $data['os'][0];

		if (!isset($data[dbpass_confirm]))
			unset($data[dbpass]);

		$config = '';
		foreach ($data AS $key => $val) {
			if (strstr($key, 'NAT-map'))
				$val = implode(',', $val);
			$config .= urlencode($key).'='.urlencode($val).'&';
			$cfg[$key] = $val;
		}
		$config = substr($config, 0, -1);
		commit('config', $config);

		sleep(2);

		if ($cfg['httpd_mode'] != 'webcp') {
			$tmp = "config.inc.php";
			include($tmp);
		}
	}
} elseif (isset($data) && $userdata['type'] == 'demo') {
	echo "<center>".$T['err']['demo user']."</center>";
}
?>
<form action="<?=$current_url;?>" method="post" name="webcp" onSubmit="submitonce(this);">
<!-- SERVER CONFIG -->
<!-- FIXME CONVERT TO LANG FILE USAGE -->
<div align="center">
<table border="0" cellpadding="0" cellspacing="0"><tr><td>
<table border="0" cellpadding="0" cellspacing="0" class="tblbg"><tr><td>
<table border="0" cellspacing="1">
	<tr>
		<td colspan="3" class="tbltop">&nbsp;Server Configuration&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;Server Domain&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[sysname]" size="25" maxlength="255" value="<?=(isset($data['sysname'])?$data['sysname']:$cfg['sysname']);?>">&nbsp;</td>
		
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;Admin E-Mail&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[adminmail]" size="25" maxlength="255" value="<?=(isset($data['adminmail'])?$data['adminmail']:$cfg['adminmail']);?>">&nbsp;</td>

	</tr>
	<tr>
		<td class="row1"><b>&nbsp;Operating System&nbsp;</b></td>
		<td class="row2">&nbsp;<select name="data[os]">
			<option value="linux/RHEL" <?=(($cfg['os'] == "linux" && $cfg['osversion'] == "RHEL") ? "selected" : "")?>>Linux - RHEL</option>
			<option value="linux/FedoraCore" <?=(($cfg['os'] == "linux" && $cfg['osversion'] == "FedoraCore") ? "selected" : "")?>>Linux - Fedora Core</option>
			<option value="linux/RedHat" <?=(($cfg['os'] == "linux" && $cfg['osversion'] == "RedHat") ? "selected" : "")?>>Linux - Red Hat</option>
			<option value="linux/Debian" <?=(($cfg['os'] == "linux" && $cfg['osversion'] == "Debian") ? "selected" : "")?>>Linux - Debian</option>
			<option value="linux/Suse" <?=(($os == "linux" && $cfg['osversion'] == "Suse") ? "selected" : "")?>>Linux - Suse</option>
			<option value="linux/Slackware" <?=(($cfg['os'] == "linux" && $cfg['osversion'] == "Slackware") ? "selected" : "")?>>Linux - Slackware</option>
			<option value="linux/Other" <?=(($cfg['os'] == "linux" && $cfg['osversion'] == "Other") ? "selected" : "")?>>Linux - Other</option>
			<option value="freebsd/FreeBSD4" <?=(($cfg['os'] == "freebsd" && $cfg['osversion'] == "FreeBSD4") ? "selected" : "")?>>FreeBSD - 4.0+</option>
			<option value="freebsd/OpenBSD" <?=(($cfg['os'] == "freebsd" && $cfg['osversion'] == "OpenBSD") ? "selected" : "")?>>OpenBSD</option>
			<option value="freebsd/NetBSD" <?=(($cfg['os'] == "freebsd" && $cfg['osversion'] == "NetBSD") ? "selected" : "")?>>NetBSD</option>
			<option value="solaris/10" <?=(($cfg['os'] == "solaris" && $cfg['osversion'] == "10") ? "selected" : "")?>>Solaris - 10+</option>
			<option value="mac/OSX" <?=(($cfg['os'] == "mac" && $cfg['osversion'] == "OSX") ? "selected" : "")?>>Mac OS X</option>
			<option value="linux/Unknown" <?=(($cfg['os'] == "linux" && $cfg['osversion'] == "Unknown") ? "selected" : "")?>>Other</option>
		</select>&nbsp;</td>
	
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;Default Language&nbsp;</b></td>
		<td class="row2">&nbsp;<select name="data[defaultlang]">
			<option value="danish">Danish</option>
			<option value="english" selected>English</option>
			<option value="french">French</option>
			<option value="german">German</option>
			<option value="norwegian">Norwegian</option>
			<option value="russian">Russian</option>
			<option value="spanish">Spanish</option>
			<option value="swedish">Swedish</option>
		</select>&nbsp;</td>
		

	</tr>
<? if ($userdata['type'] != 'demo') { ?>
	<tr>
		<td class="row1"><b>&nbsp;Secret Key&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[key]" size="25" maxlength="255" value="<?=(isset($data['key'])?$data['key']:$cfg['key']);?>">&nbsp;</td>
		
	</tr>
<? } ?>
</table>
</td></tr></table><br>

</td></tr></table>
</div>

<!-- DATABASE CONFIG -->
<div align="center">
<table border="0" cellpadding="0" cellspacing="0"><tr><td>
<table border="0" cellpadding="0" cellspacing="0" class="tblbg"><tr><td>
<table border="0" cellspacing="1">
	<tr>
		<td colspan="3" class="tbltop">&nbsp;Database Configuration&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;Database Host&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[dbhost]" size="25" maxlength="255" value="<?=(isset($data['dbhost'])?$data['dbhost']:$cfg['dbhost']);?>">&nbsp;</td>

	</tr>
	<tr>
		<td class="row1"><b>&nbsp;Database User&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[dbuser]" size="25" maxlength="255" value="<?=(isset($data['dbuser'])?$data['dbuser']:$cfg['dbuser']);?>">&nbsp;</td>


	</tr>
	<tr>
		<td class="row1"><b>&nbsp;Database Password&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="password" name="data[dbpass]" size="15" maxlength="255">&nbsp;&nbsp;confirm <input type="checkbox" name="data[dbpass_confirm]" value="1"></td>


	</tr>
	<tr>
		<td class="row1"><b>&nbsp;Database Name&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[dbname]" size="25" maxlength="255" value="<?=(isset($data['dbname'])?$data['dbname']:$cfg['dbname']);?>">&nbsp;</td>

	</tr>
</table>
</td></tr></table><br>

</td></tr></table>
</div>

<!-- NETWORK CONFIG -->
<div align="center">
<table border="0" cellpadding="0" cellspacing="0"><tr><td>
<table border="0" cellpadding="0" cellspacing="0" class="tblbg"><tr><td>
<table border="0" cellspacing="1">
	<tr>
		<td colspan="3" class="tbltop">&nbsp;NAT Configuration&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;Enable NAT&nbsp;</b></td>
		<td class="row2">&nbsp;<select name="data[NAT]">
			<option value="true" <?=(isset($data['NAT'])?($data['NAT']==true?'selected':''):($cfg['NAT']==true?'selected':'')); ?>>Yes</option>
			<option value="false" <?=(isset($data['NAT'])?($data['NAT']==false?'selected':''):($cfg['NAT']==false?'selected':'')); ?>>No</option>
		</select>&nbsp;</td>
		

	</tr>
	<tr>
		<td class="tbltop" colspan="3">&nbsp;NAT IP Mappings&nbsp;</td>
	</tr>
<?php
for ($map = 1; $map <= 6; $map++) {
	if ($cfg['NAT-map'.$map] != '')
		$NATmap = explode(',', $cfg['NAT-map'.$map]);
?>
	<tr>
		<?php $mapvar = 'NAT-map'.$map.'][0'; ?>
		<td class="row2" colspan="2">
		<?php echo $map; ?>&nbsp;<input type="text" name="data[<?php echo $mapvar; ?>]" size="25" maxlength="15" value="<?=(isset($data['NAT-map'.$map.'][0'])?$data['NAT-map'.$map.'][0']:$NATmap[0]);?>">
			&nbsp;&rsaquo;&nbsp;
		<?php $mapvar = 'NAT-map'.$map.'][1'; ?>
		<input type="text" name="data[<?php echo $mapvar; ?>]" size="25" maxlength="15" value="<?=(isset($data['NAT-map'.$map.'][1'])?$data['NAT-map'.$map.'][1']:$NATmap[1]);?>">
		</td>

	</tr>
<?php
	unset($NATmap);
}
?>
</table>
</td></tr></table><br>

<div align="right"><input type="submit" value="Submit"></div>

</td></tr></table>
</div>

</form>
